<?php if (! defined ( 'BASEPATH' )) exit ( 'No direct script access allowed' );

class SiteController extends CI_Controller {
    
    protected $data = array ();
        
    public function __construct() {
        parent::__construct ();
	if ($this->session->userdata ( 'userId' ) != FALSE) {
            $user = $this->doctrine->em->find ( 'Entities\Usuario', $this->session->userdata ( 'userId' ) );
            if (! is_null ( $user )) {
                $this->data['user'] = $user;
            }
	}
        $this->data ['baseUrl'] = $this->config->base_url ();
    }
	
    protected function auth() {
        if (! isset ( $this->data ['user'] )) {
            redirect ( '/' );
	};
    }

    public function index() {
        if (isset ( $this->data ['user'] )) {
                redirect ( '/login' );
        };

        $this->loadView();
    }
        
    protected function loadView($view = null) {
        if ($view == null) {
            $view = 'login';
        }

        $this->load->view ( 'template/header', $this->data );
        $this->load->view ( $view, $this->data );
        $this->load->view ( 'template/footer', $this->data );
    }
}